class Gists
  attr_accessor :github, :comments

  def initialize(github)
    @github = github
    @comments = GistsComments.new(github)
  end

  def listGists(user=nil)
    url = user != nil ? 'users/%s/gists' : 'gists'
    @github.get(url)
  end

  def listPublicGists()
    @github.get('gists/public')
  end

  def listStarredGists()
    @github.get('gists/starred')
  end

  def getGist(id)
    @github.get('gists/%s' % id)
  end

  def createGist(public, files, description=nil)
    params = {
        :description => description,
        :public => public,
        :files => files
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    @github.post('gists', data)
  end

  def editGist(id, files=nil, description=nil)
    params = {
        :description => description,
        :files => files
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    @github.patch('gists/%s' % id, data)
  end

  def starGist(id)
    @github.put('gists/%s/star' % id)
  end

  def unStarGist(id)
    @github.delete('gists/%s/star' % id)
  end

  def checkIfGistStarred(id)
    @github.get('gists/%s/star' % id)
  end

  def forkGist(id)
    @github.post('gists/%s/fork' % id)
  end

  def deleteGist(id)
    @github.delete('gists/%s' % id)
  end
end